import { defineStore } from 'pinia'
import {nextTick} from "vue";


export const useChatStore = defineStore('chat', {
    state: () => {
        return {
            showWelcome: true,
            deepSeek: false,
            currentChatList:[
                {
                    role: 'user',
                    content:'你好'
                }, {
                    role: 'koala',
                    content:'你好，很高兴认识你！'
                }
            ],
        }
    },
    actions: {

        createChat() {
            $chatClient.createChat({})
        },
        // 发送提问
        async sendQuestion(intent) {
            const obj = {
                role: 'user',
                content: intent.content
            }
            this.currentChatList.push(obj)

            const res = await  $chatClient.chat(intent.content)

            this.currentChatList.push({
                role: 'koala',
                content: res
            })

        },
        async scrollToBottom(scrollContainer){
            await nextTick(); // 等待 DOM 更新
            if (scrollContainer) {
                scrollContainer.scrollTo({
                    top: scrollContainer.scrollHeight,
                    behavior: "smooth",
                });
            }
        }
    },
})
